<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title th:replace="common/base::pagetitle"></title>
    <link th:replace="common/base::static"/>
</head>
<style type="text/css">
    .layui-table-cell{
        height: inherit;
        white-space: normal;
        vertical-align:top;
    }
    /**表头文字样式*/
    .layui-table th{
        font-weight: bold;
        font-size: 14px;
        text-align: center;
    }
    /**表格文字样式*/
    .layui-table td{
        font-size: 13px;
        text-align: center;
    }
</style>
<body style="background-color: #f2f2f2;">

<div id="kPage" class="layui-fluid" style="padding: 0">
    <div class="layui-row">
        <div class="layui-col-md12" id="kMainContentCol">
            <div class="layui-fluid kvf-fluid-padding15">
                <div class="layui-card">
                    <form>
                        <div class="layui-form layui-card-header kvf-card-header-auto">
                            <div class="layui-form-item">

                                <!--<div class="layui-inline">
                                    <label class="layui-form-label">关联任务id</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="taskId" placeholder="请输入关联任务id" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">任务名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="taskName" placeholder="请输入任务名称" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">视频链接</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="videoLink" placeholder="请输入视频链接" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">客户网名</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="nickname" placeholder="请输入意向客户网名" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">评论的内容</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="content" placeholder="请输入评论的内容" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">客户手机号</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="cusPhone" placeholder="请输入意向客户手机号" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">微信号</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="vx" placeholder="请输入微信号" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">命中关键词</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="hitKeyword" placeholder="请输入命中关键词" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">咨询时间</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="consuTime" id="consuTime" placeholder="请输入咨询时间" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">分析时间</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="analyseTime" id="analyseTime" placeholder="请输入分析时间" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">状态：</label>
                                    <div class="layui-input-inline">
                                        <select class="layui-select" name="keywordType" placeholder="0未联系 1已联系">
                                            <option th:value="0">未联系</option>
                                            <option th:value="1">已联系</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">开始时间</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="beginTime" id="createTime" placeholder="请输入咨询开始时间" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">结束时间</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="endTime" id="updateTime" placeholder="请输入咨询结束时间" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">创建时间</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="createTime" id="createTime" placeholder="请输入创建时间" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">创建人</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="createUser" placeholder="请输入创建人" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">修改时间</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="updateTime" id="updateTime" placeholder="请输入修改时间" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">修改人</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="updateUser" placeholder="请输入修改人" autocomplete="off" class="layui-input">
                                    </div>
                                </div>-->

                                <!--<div class="layui-inline">
                                    <label class="layui-form-label">客户主页链接</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="custHome" placeholder="请输入客户主页链接" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">客户二维码链接</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="qrCode" placeholder="请输入客户二维码链接" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">意向客户表id</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="id" placeholder="请输入意向客户表id" autocomplete="off" class="layui-input">
                                    </div>
                                </div>-->

                                <div class="layui-inline">
                                    <!--<button class="layui-btn " lay-submit="" lay-filter="kTableSearchFilter">
                                        <i class="layui-icon layui-icon-search"></i>
                                    </button>
                                    <button class="layui-btn " type="reset" data-event="refresh">
                                        <i class="layui-icon layui-icon-refresh-1"></i>
                                    </button>-->
                                </div>
                            </div>
                        </div>
                    </form>

                    <div class="layui-card-body">
                        <table id="kContentTable" lay-filter="kContentTable" class="layui-table-cell"></table>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

<script th:replace="common/base::context"></script>
<script th:replace="common/base::mainjs"></script>

<!--头部工具栏模板-->
<script type="text/html" id="headToolbarTpl">
    <button type="button" lay-event="batchdel" class="layui-btn layui-btn-sm layui-btn-danger" ><i class="layui-icon layui-icon-delete"></i>删除</button>
    <button type="button" lay-event="editStatus" class="layui-btn layui-btn-sm layui-btn-normal" ><i class="layui-icon layui-icon-edit"></i>设置为已联系</button>
    <button type="button" lay-event="editnoStatus" class="layui-btn layui-btn-sm layui-btn-danger" ><i class="layui-icon layui-icon-edit"></i>设置为未联系</button>
    <button type="button" data-event="refresh" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-refresh"></i>刷新</button>
</script>

<!--表格行工具栏模板-->
<script type="text/html" id="rowToolbarTpl">
    <!--<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
</script>

<!--表格列格式化模板 start-->
<!--表格列格式化模板 end-->

<script type="text/javascript" th:inline="javascript">
    layui.use(['element', 'form', 'layer', 'table', 'laydate'], function () {
        var elemet = layui.element, form = layui.form, layer = layui.layer, table = layui.table, laydate = layui.laydate;
        var tableId = 'kContentTable';
        var area = ['449px', '95%'];


        // 实例化table
        var tableIns = table.render($.extend(config.layui.table, {
            elem: '#' + tableId
            ,url: BASE_WEB + 'ks/intentionCust/list/data' //数据接口
            ,toolbar: '#headToolbarTpl'
            ,cols: [[ //表头
                {type:'checkbox',Width: 70,unresize: true}
                ,{field: 'taskName', title: '任务名称', Width: 100,unresize: true}
                ,{field: 'custAvatar', title: '客户头像', Width: 90,align:'center',unresize: true, templet:function (d) {
                        return '<img src="'+d.custAvatar+'" onclick="showimg(this)" title="点我" Width="35" height="35"/>'}}
                ,{field: 'nickname', title: '客户网名', Width: 121,unresize: true}
                //,{field: 'taskId', title: '关联任务id', Width: 130}
                ,{field: 'videoLink', title: '视频链接',Width: 150,unresize: true,templet: function(d){
                        return '<a href='+d.videoLink+' style="color: blue" target="_blank">'+d.label+'</a>'
                    }}
                ,{field: 'content', title: '评论内容', Width: 130,unresize: true}
                ,{field: 'hitKeyword', title: '命中关键词', Width: 109,unresize: true}
                ,{field: 'consuTime', title: '咨询时间', Width: 105,unresize: true,sort: true}
                ,{field: 'analyseTime', title: '分析时间', Width: 160,unresize: true,sort: true}
                ,{field: 'label', title: '说明', Width: 150,unresize: true}
                ,{field: 'vx', title: '微信号', Width: 85,unresize: true,templet: function(d){
                        if(d.vx==null){
                            return '-'
                        }else if(d.vx!=null) {
                            return d.vx
                        }}}
                ,{field: 'cusPhone', title: '手机号', Width: 85,unresize: true,templet: function(d){
                        if(d.cusPhone==null){
                            return '-'
                        }else if(d.cusPhone!=null) {
                            return d.cusPhone
                        }}}
                //,{field: 'custHome', title: '客户主页链接', Width: 150}
                ,{field: 'status', title: '状态', Width: 102,sort: true,unresize: true,templet: function(d){
                        if(d.status==0){
                            return '<span style="color: #FF3366;font-size: 13px;">未联系</span>'
                        }else if(d.status==1) {
                            return '<span style="color: #00B83F;font-size: 13px;">已联系</span>'
                        }}}
                //,{field: 'createTime', title: '创建时间', Width: 150}
                //,{field: 'createUser', title: '创建人', Width: 130}
                //,{field: 'updateTime', title: '修改时间', Width: 130}
                //,{field: 'updateUser', title: '修改人', Width: 130}

                ,{field: 'custHome', title: '私信客户', Width: 150,unresize: true,templet: function(d){
                        return '<a href='+d.custHome+' style="color: blue" target="_blank"><button type="button" class="layui-btn layui-btn-sm">私信客户</button></a>'
                    }}
                //,{field: '', title: '操作', Width: 235, fixed: 'right', templet: '#rowToolbarTpl'}
            ]]
        }));




        // 监听表格头部事件
        table.on('toolbar(' + tableId + ')', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var checkData = checkStatus.data; // 得到选中的数据
            switch(obj.event) {
                case 'editStatus':
                    if(checkData.length === 0){
                        return kvfKit.warningMsg('请选择数据');
                    }
                    var ids = [];
                    $.each(checkData, function(i, n){
                        ids[i] = n.id;
                    });
                    //执行 Ajax 后重载
                    $.ajax({
                        type: req.type.post,
                        url: BASE_WEB + 'ks/intentionCust/editStatus',
                        data: {ids: ids.toString()},
                        success: function (r) {
                            if (r.code === req.status.ok) {
                                table.reload(tableId);
                                kvfKit.sucessMsg('已修改');
                            } else {
                                kvfKit.errorMsg(r.msg);
                            }
                        }
                    });
                    break;
                case 'editnoStatus':
                    if(checkData.length === 0){
                        return kvfKit.warningMsg('请选择数据');
                    }
                    var ids = [];
                    $.each(checkData, function(i, n){
                        ids[i] = n.id;
                    });
                    //执行 Ajax 后重载
                    $.ajax({
                        type: req.type.post,
                        url: BASE_WEB + 'ks/intentionCust/editnoStatus',
                        data: {ids: ids.toString()},
                        success: function (r) {
                            if (r.code === req.status.ok) {
                                table.reload(tableId);
                                kvfKit.sucessMsg('已修改');
                            } else {
                                kvfKit.errorMsg(r.msg);
                            }
                        }
                    });
                    break;
                case 'batchdel':
                    if(checkData.length === 0){
                        return kvfKit.warningMsg('请选择数据');
                    }
                    layer.confirm('确定删除吗？', function(index) {
                        var ids = [];
                        $.each(checkData, function(i, n){
                            ids[i] = n.id;
                        });

                        //执行 Ajax 后重载
                        $.ajax({
                            type: req.type.post,
                            url: BASE_WEB + 'ks/intentionCust/batchdel',
                            data: {ids: ids.toString()},
                            success: function (r) {
                                if (r.code === req.status.ok) {
                                    table.reload(tableId);
                                    kvfKit.sucessMsg('已删除');
                                } else {
                                    kvfKit.errorMsg(r.msg);
                                }
                            }
                        });
                    });
                    break;
            }
        });

        // 表格行按钮 监听事件
        table.on('tool(' + tableId + ')', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if (layEvent === 'edit') {
                layer.open({
                    type: 2
                    ,title: '编辑'
                    ,content: BASE_WEB + 'ks/intentionCust/edit?id=' + data.id
                    ,maxmin: true
                    ,area: area   // 宽高
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#kFormSubmit");
                        submit.click();
                    }
                });
            }
            if (layEvent === 'del') {
                layer.confirm('确定删除吗？', function(index) {
                    //执行 Ajax 后重载
                    $.ajax({
                        type: req.type.post,
                        url: BASE_WEB + 'ks/intentionCust/del/' + data.id,
                        async: false,
                        success: function (r) {
                            if (r.code === req.status.ok) {
                                table.reload(tableId);
                                kvfKit.sucessMsg('已删除');
                            } else {
                                kvfKit.errorMsg(r.msg);
                            }
                        }
                    });
                });
            }
        });


        // 监听查询
        form.on('submit(kTableSearchFilter)', function (obj) {
            renderTableData(obj.field);
            return false;
        });

        var active = {
            refresh: function () {
                var $form = $('form');
                $form[0].reset();
                renderTableData(kvfKit.getFormJson($form));
            }
        };

        kvfKit.activeInit(active);

        function renderTableData(params) {
            params = params ? params : {};

            tableIns.reload({
                where: params,
                page: {curr: 1}
            });
        }

        // 绑定监听回车事件
        kvfKit.bindEnterEventForLayuiForm();

    });

    //点解图片放大
    window.showimg = function (t) {
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: '716px',
            skin: 'layui-layer-nobg',
            shadeClose: true,
            content: '<img style="display: inline-block; width: 100%; height: 100%;" src="' + t.src + '">'
        });
    }

</script>

</body>
</html>